// 在 src/store/index.js 中创建一个简单的 store
import { UserInfoState } from '@/api/login/types';
import { defineStore } from 'pinia'
 
interface State {
  userForm: UserInfoState;
  isLogin:boolean;
}
 
export const useMyStore = defineStore('myStore', {
  state: (): State => ({
    userForm: {
      username: '',
      password: '',
    },
    isLogin:false
  }),
  actions: {
    // 动作
    setUserInfo(data:UserInfoState) {
      this.userForm = data
    },
    setIsLogin(data:boolean) {
      this.isLogin = data
    },
    cleanUserInfo(){
      this.userForm = {
        username: '',
        password: '',
      }
    }
  },
  //持久化
  persist:{
    enabled:true,
    strategies:[
        {   
            key:'myStore',//存储的key值
            storage:localStorage,//存储的位置
            paths:['userForm'] //默认持久化state的全部，paths指定持久化的对象
        }
    ]
  },
})